//
//  AXFSetAddressViewController.m
//  adress
//
//  Created by 候锐 on 16/11/19.
//  Copyright © 2016年 候锐. All rights reserved.
//

#import "AXFSetAddressViewController.h"
#import "AXFAddAddressCell.h"
#import "AXFAddGenterCell.h"
#import "UIColor+CZAddition.h"
#import "AXFAddressModel.h"
#import "AXFAddressDelete.h"
@interface AXFSetAddressViewController ()

@end

@implementation AXFSetAddressViewController

- (instancetype)init{
    return [super initWithStyle:UITableViewStyleGrouped];
}
- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupUI];
    
}
- (void)backAction{
 
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)setupUI{
    
    self.navigationItem.title = @"添加地址";
    self.tableView.sectionFooterHeight = 10;
    self.tableView.sectionHeaderHeight = 0;
    
    UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:nil action:nil];

    rightBar.tintColor = [UIColor blackColor];
  
    
    [self.navigationItem setRightBarButtonItem:rightBar];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"v2_goback"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor grayColor];
    
    
    
    
    self.tableView.backgroundColor = [UIColor cz_colorWithHex:0xefefef];
    
    
    self.tableView.tableFooterView = [[UIView alloc] init];

    [self.tableView registerNib:[UINib nibWithNibName:@"AXFAddAddressCell" bundle:nil] forCellReuseIdentifier:@"addcell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"AXFAddGenterCell" bundle:nil] forCellReuseIdentifier:@"gentercell"];

    
    [self.tableView registerNib:[UINib nibWithNibName:@"AXFAddressDelete" bundle:nil] forCellReuseIdentifier:@"deletecell"];
    
    self.tableView.estimatedRowHeight = 61;
    

}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    if(_model == nil){
        return 1;
    }else{
        return 2;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if(section == 0){
        return 6;
    }else
        return 1;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == 1 && indexPath.section == 0){
        AXFAddGenterCell *cell = [tableView dequeueReusableCellWithIdentifier:@"gentercell" forIndexPath:indexPath];
        
        return cell;
    }
    if (indexPath.section == 0) {
    AXFAddAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:@"addcell" forIndexPath:indexPath];
    switch (indexPath.row) {
        case 0:
            cell.text.text = @"联系人";
            cell.textField.placeholder = @"收货人姓名";
            cell.textField.text = _model.name;
            cell.textField.keyboardType = UIKeyboardTypeDefault;
            return cell;
        case 2:
            cell.text.text = @"手机号码";
            cell.textField.placeholder = @"鲜蜂侠联系您的电话";
            cell.textField.text = _model.phoneNumber;
            cell.textField.keyboardType = UIKeyboardTypePhonePad;
            return cell;
        case 3:
            cell.text.text = @"所在城市";
            cell.textField.placeholder = @"请选择城市";
            cell.textField.text = _model.city;
            return cell;
        case 4:
            cell.text.text = @"所在地区";
            cell.textField.placeholder = @"请选择您的住宅小区、大厦或学校";
            cell.textField.text = _model.address;
            cell.textField.keyboardType = UIKeyboardTypeDefault;
            return cell;
        case 5:
            cell.text.text = @"详细地址";
            cell.textField.placeholder = @"请输入楼号门牌号等详细信息";
            cell.textField.text = _model.detailsAdd;
            cell.textField.keyboardType = UIKeyboardTypeDefault;
            return cell;
    }
}
    
    AXFAddressDelete *cell = [tableView dequeueReusableCellWithIdentifier:@"deletecell" forIndexPath:indexPath];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 10;
    }
    return 0;

}




@end
